home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / tchelp.arc / TCHELP.C < prev    next >
Text File  |  1987-06-08  |  4KB  |  137 lines

  1. /*
  2. tchelp.c
  3. by Edward V Dong, 08 June 1987
  4.  
  5. -----------------------------------------------------------------------
  6.  tchelp.c is based on about.c, originally written for DeSmet C, but
  7.  converted to Turbo C version 1.0.  The following is the original
  8.  discussion on about.c
  9. -----------------------------------------------------------------------
  10.    Usage:           about  <name>  [<catfile>]
  11.  
  12.    Examples:        about calloc
  13.                     about *
  14.                     about * b:c.cat
  15.                     about fourier b:math.dat
  16.  
  17.     Description:    For each line in <catfile> beginning as ":<name>",
  18.                     successive lines are displayed until the next line
  19.                     begins with ":";  if <name> is *, all entries are
  20.                     displayed;  <catfile> defaults to "about.dat".
  21.  
  22.     Purpose:        The file about.dat contains synopses of C functions,
  23.                     thus making "about" an elementary "help facility".
  24.  
  25.                     However, <catfile> may be any list of :<name>'s of
  26.                     interest, with each name on a separate line, and
  27.                     each followed by its respective text to be displayed.
  28.  
  29.     Limitations:    A simple linear search is used, so probably no more
  30.                     than a few hundred names can be handled usefully.
  31.  
  32.     Language:       C (DeSmet 2.4)
  33.  
  34.     Author:         R. E. Sawyer
  35.                     3620 Spencer St. 30, Torrance, CA 90503
  36.                     1 Jan 85
  37. -----------------------------------------------------------------------
  38. */
  39.  
  40. #include <stdio.h>
  41.  
  42. #define CATFILE "tc.dat"
  43. #define DEFCHAR ':'
  44. #define BUFLEN 82
  45.  
  46. FILE *fin;
  47.  
  48. main(ac, av)
  49.     int ac;
  50.     char *av[];
  51.     {
  52.     char *catfile, *more;
  53.     char buf[BUFLEN];
  54.     char *print_text();
  55.     int showall;
  56.     int done;
  57.  
  58.     showall = 0;
  59.     done = 0;
  60.  
  61.     if ((ac < 2) || (ac > 3))
  62.         {
  63.         printf("\nUsage:    tchelp <name>  [<catfile>]\n");
  64.         printf("\nFor each line in <catfile> beginning as \":<name>\",");
  65.         printf("\nsuccessive lines are displayed until the next line");
  66.         printf("\nbegins with \":\";  if <name> is *, all entries are");
  67.         printf("\ndisplayed;  <catfile> defaults to \"tc.dat\".\n");
  68.         printf("\nbased on original by R.E.Sawyer (about.c) revised");
  69.         printf("\nby Edward V. Dong, 8 June 1987, for Turbo C.\n");
  70.         exit();
  71.         }
  72.     else if (ac == 2)
  73.         {
  74.         if ((fin = fopen(catfile = CATFILE, "rb")) == 0)
  75.             {
  76.             printf("\n---File %s not found", catfile);
  77.             exit();
  78.             }
  79.         }
  80.     else if (ac ==3)
  81.         {
  82.         if ((fin = fopen(catfile = av[2], "rb")) == 0)
  83.             {
  84.             printf("\n---File %s not found", catfile);
  85.             exit();
  86.             }
  87.         }
  88.     if (*av[1] == '*')
  89.         showall = 1;
  90.     printf("\n(Catalogue file:  %s)\n\n", catfile);
  91.     more = fgets(buf, BUFLEN - 1, fin);
  92.     while (more!=NULL)
  93.         {
  94.         if ((buf[0] == DEFCHAR)
  95.             && ((comp(av[1], buf + 1) == 0) || showall))
  96.             {
  97.             more = print_text(buf);
  98.             if (!showall)
  99.                 {
  100.                 done = 1;
  101.                 break;
  102.                 }
  103.             }
  104.         else
  105.             more = fgets(buf, BUFLEN - 1, fin);
  106.         }
  107.     if ((done != 1) && !showall)
  108.         printf("\"%s\" is not catalogued\n\n", av[1]);
  109.     fclose(fin);
  110.     }
  111.     
  112. int comp(s, t)
  113.     char *s, *t;
  114.     {
  115.     int i;
  116.  
  117.     for (i = 0; (t[i] > ' ') && (t[i] <= '~'); ++i)
  118.         ;
  119.     t[i] = '\0';
  120.     return strcmp(s, t);
  121.     }
  122.  
  123. #include <string.h>
  124. char *print_text(buf)
  125.     char buf[];
  126.     {
  127.     char *more;
  128.     printf("%s:\n", &buf[1]);
  129.     while (((more = fgets(buf, BUFLEN - 1, fin)) != NULL)
  130.         && (buf[0] != DEFCHAR))
  131.         {
  132.         if (strrchr(buf,10)!=NULL) *strrchr(buf,10) = 0;
  133.         puts(buf);
  134.         }
  135.     return more;
  136.     }
  137.